/**
 * @author  zhanshi Liu
 * @date    2020/04/17
 * @website www.jhmsona.cn
 */
var vm = new Vue({
    el:'#vm',
    data:{
        tabPosition: 'left',
        qiniu:'qiniu',
        ali:'ali',
        youpai:'youpai',
        local:'local',
        activeName: 'first',
        storageType:'',
        verifyForm:{
            qiniuyun:0,
            aliyun:1,
            youpaiyun:2,
            pricloud:3,
        },
        ruleForm: {},
        qiniuRules: {
            qiniuBucket: [{ required: true, message: '请输入七牛云Bucket', trigger: 'blur' }],
            qiniuAccessKey: [{ required: true, message: '请输入七牛云AccessKey', trigger: 'blur' }],
            qiniuSecretKey: [{ required: true, message: '请输入七牛云SecretKey', trigger: 'blur' }],
            qiniuCDN: [{ required: true, message: '请输入七牛云加速域名(CDN)', trigger: 'blur' }],
            qiniuStoragePath:[{ required: true, message: '请输入七牛云存储路径', trigger: 'blur' }],
        },
        aliRules:{
            aliBucket:[{ required: true, message: '请输入阿里云Bucket名称', trigger: 'blur' }],
            aliBucketDomain:[{ required: true, message: '请输入阿里云Bucket域名', trigger: 'blur' }],
            aliAccessKey:[{ required: true, message: '请输入阿里云AccessKey', trigger: 'blur' }],
            aliSecretKey:[{ required: true, message: '请输入阿里云SecretKey', trigger: 'blur' }],
            aliEndpoint:[{ required: true, message: '请输入阿里云Endpoint地域节点', trigger: 'blur' }],
            aliStoragePath:[{ required: true, message: '请输入阿里云存储路径', trigger: 'blur' }],
        },
        ypRules:{
            ypBucket:[{ required: true, message: '请输入又拍云Bucket名称', trigger: 'blur' }],
            ypBucketDomain:[{ required: true, message: '请输入又拍云Bucket域名', trigger: 'blur' }],
            ypUserName:[{ required: true, message: '请输入又拍云操作员账号', trigger: 'blur' }],
            ypPassword:[{ required: true, message: '请输入又拍云操作员密码', trigger: 'blur' }],
            ypStoragePath:[{ required: true, message: '请输入又拍云存储路径', trigger: 'blur' }],
        },
        othersRules:{
            fileSuffix:[{ required: true, message: '请输入允许上传的文件类型', trigger: 'blur' }]
        },

    },
    created:function (){
        this.getConfigs();
    },
    methods:{
        getConfigs(){
            axios.get('/oss/config/map').then(res=>{
                this.ruleForm=res.data;
                this.storageType = this.ruleForm.storageType;
            })
        },
        changeCloud(){
            this.$confirm('此操作将切换云存储类型,可能会导致部分功能不可用, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.ruleForm.storageType = this.storageType;
                axios.put('/oss/config/update',this.ruleForm);
            }).catch(() => {
                this.storageType = this.ruleForm.storageType;
            })

        },
        onSubmit(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    axios.put('/oss/config/update',this.ruleForm).then(res=> {
                        this.$notify({title:'成功',message:res.data.msg,type:'success'});
                    })
                }
            });
        },
    }
})

